<template>
  <div class="pattern">
    <FormPanel :list="topFilterList" :cols="1" :collapse="false" :isSubmitBtn="false" @filterChange="changeHandle"></FormPanel>
  </div>
</template>
<script>
import { getlabourpriceList, getqueryDiscountModeList } from '@/api/repair/repairReception/evaluation/index';
export default {
  props: ['getdata'],
  data() {
    return {
      topFilterList: this.createdFrom()
    };
  },
  watch: {
    getdata: {
      handler: function(newval, oldVal) {
        if (newval.type == 'add') {
          this.topFilterList.map((item, key) => {
            item.disabled = false;
          });
        } else if (newval.type == 'emit') {
          this.topFilterList.map((item, key) => {
            item.disabled = false;
          });
        } else {
          this.topFilterList.forEach(x => {
            x.initialValue = '';
          });
          this.topFilterList.map((item, key) => {
            item.disabled = true;
          });
        }
        console.log(newval);
      },
      deep: true
    }
  },
  created() {
    this.getDictlist();
    this.initData();
  },
  methods: {
    createdFrom() {
      return [
        {
          type: 'SELECT',
          label: '优惠模式',
          fieldName: 'DISCOUNT_MODE_CODE',
          initialValue: '',
          itemList: [],
          disabled: true,
          style: {
            'min-width': '100px'
          }
        },
        {
          type: 'SELECT',
          label: '工时单价',
          fieldName: 'LABOUR_PRICE',
          initialValue: '',
          disabled: true,
          itemList: [],
          style: {
            'min-width': '100px'
          }
        }
      ];
    },
    changeHandle(val) {},
    async getDictlist() {
      let res5 = (await getlabourpriceList(this.params)).map(x => ({ text: x.LABOUR_PRICE, value: x.LABOUR_PRICE_CODE }));
      let res = await getqueryDiscountModeList(this.params);
      console.log(res);
      this.topFilterList[1].itemList = res5;
    },
    initData() {
      this.topFilterList.forEach(x => {
        x.initialValue = this.getdata[x.fieldName];
      });
    }
  }
};
</script>
<style lang="less" scope>
.pattern {
  width: 100%;
  height: 100px;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  margin-bottom: 10px;
  padding-top: 10px;
  padding-right: 20px;
  box-sizing: border-box;
}
</style>
